package com.hospital.pet.love.lovepethospital.controller;

import com.hospital.pet.love.lovepethospital.dto.user.ChangePasswordDto;
import com.hospital.pet.love.lovepethospital.dto.user.UserDto;
import com.hospital.pet.love.lovepethospital.resp.Result;
import com.hospital.pet.love.lovepethospital.resp.ResultCodeEnum;
import com.hospital.pet.love.lovepethospital.service.UserService;
import com.hospital.pet.love.lovepethospital.vo.user.LoginVo;
import com.hospital.pet.love.lovepethospital.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author RoselleShaw
 * @create 2024-04-19 10:58
 */
@Tag(name = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<LoginVo> login(@RequestBody UserDto userDto) {
        LoginVo loginVo = userService.login(userDto);
        return Result.build(loginVo, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/register")
    @Operation(summary = "客户注册")
    public Result<Void> register(@RequestBody UserDto userDto) {
        userService.register(userDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/logout")
    @Operation(summary = "用户注销")
    public Result<Void> logout(@RequestHeader String token) {
        userService.logout(token);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/change-password")
    @Operation(summary = "用户修改密码", parameters = @Parameter(name = "token", in = ParameterIn.HEADER, required = true))
    public Result<Void> changePassword(@RequestBody ChangePasswordDto changePasswordDto) {
        userService.changePassword(changePasswordDto.getPassword());
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/get-user-info")
    @Operation(summary = "获取用户详细信息")
    public Result<UserInfoVo> getUserInfo(){
        UserInfoVo userInfoVo = userService.getUserInfo();
        return Result.build(userInfoVo, ResultCodeEnum.SUCCESS);
    }

}
